package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yl.auth.model.entity.HuiFangJiLu;
import com.yl.auth.model.entity.ZiXun;
import com.yl.auth.service.HuiFangJiLuService;
import com.yl.auth.service.ZiXunService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author L
 * @since 2023-06-19
 */
@RestController
@RequestMapping("/admin/yanglao/huifangjilu")
@Api(tags = "市场销售-回访记录")
public class HuiFangJiLuController {
    @Resource
    private HuiFangJiLuService huiFangJiLuService;

    @Resource
    private ZiXunService ziXunService;
    @ApiOperation("查询回访记录+咨询人信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id){
        LambdaQueryWrapper<HuiFangJiLu> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(HuiFangJiLu::getZid,id);
        lambdaQueryWrapper.orderByDesc(HuiFangJiLu::getId);
        List<HuiFangJiLu> list = huiFangJiLuService.list(lambdaQueryWrapper);
        ZiXun ziXun = ziXunService.getById(id);
        Map<String,Object> map = new HashMap<>();
        map.put("list",list);
        map.put("ziXun",ziXun);
        return Result.ok(map);
    }

    @ApiOperation("新增回访记录")
    @PostMapping("/insert/{id}")
    public Result insert(@PathVariable Integer id,@RequestBody HuiFangJiLu huiFangJiLu){
        huiFangJiLu.setZid(id);
        huiFangJiLuService.save(huiFangJiLu);
        Integer zid = huiFangJiLu.getZid();
        ZiXun ziXun = ziXunService.getById(zid);
        ziXun.setFollowStatus(1);
        ziXunService.updateById(ziXun);
        return Result.ok();
    }
}

